/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SocialValueSliderPackage;

import java.awt.Component;
import java.util.Vector;
import DragBarPanelPackage.*;

/**
 * This keeps track of the drag bar button names for the altruism dialog
 * @author Evan
 */
public class SocialValueComponentTracker
{
  // These are the ascriptive characteristics
  public Vector<String> ascriptiveCategories;
  // these are the values of the ascriptive characteristics
  // This field is typically just used for intialization of buttons
  public Vector<String> componentAscriptives;
  public Component theComponent = null;
  public Vector<int[]> representedGroups = new Vector<int[]>();
  public boolean componentAscriptivesSet = false;
  public Vector<String> disabledAltruism = new Vector<String>();
  public String componentName = "";

  public SocialValueComponentTracker(Component theComponent, Vector<String> ascriptiveCategories,
                                  Vector<String> componentAscriptives, Vector<int[]> representedGroups)
  {
    this.theComponent = theComponent;
    this.ascriptiveCategories = ascriptiveCategories;
    this.componentAscriptives = componentAscriptives;
    this.representedGroups = representedGroups;

    for (int i = 0; i < ascriptiveCategories.size(); i++)
    {
      //parentStrings.add("");
      Vector<String> newChildrenStrings = new Vector<String>();
      //childrenStrings.add(newChildrenStrings);
    }
    componentAscriptivesSet = true;
    componentName = theComponent.getName();
    if (componentName == null)
      System.out.println("NULL NAME ENTERED!!!!!!!!!!!!!!!!!!!!!!!");
  }

  public SocialValueComponentTracker(Component theComponent, Vector<String> ascriptiveCategories,
                                  Vector<int[]> representedGroups)
  {
    this.theComponent = theComponent;
    this.ascriptiveCategories = ascriptiveCategories;
    this.representedGroups = representedGroups;
    componentAscriptives = new Vector<String>();
    componentAscriptivesSet = false;
    componentName = theComponent.getName();
    if (componentName == null)
      System.out.println("NULL NAME ENTERED!!!!!!!!!!!!!!!!!!!!!!!");
  }

  // supply the category, returns the name entry for that category
  public String getCategoryName(String category)
  {
    int catIndex = getIndexOf(ascriptiveCategories, category);

    if (catIndex != -1)
    {
      return componentAscriptives.get(catIndex);
    } else
    {
      return null;
    }
  }

  public int getCategoryIndex(String category)
  {
    return componentAscriptives.indexOf(category);
  }

  public Vector<String> getDisabledAltruism()
  {
    return disabledAltruism;
  }
  
  private int getIndexOf(Vector<String> v, String search)
  {
    int ret = -1;

    for (int i = 0; i < v.size(); i++)
    {
      if (v.get(i).equals(search))
      {
        return i;
      }
    }

    return ret;
  }

  // NOTE: THIS WILL NOT SET THE COMPONENT ASCRIPTIVES
  public void setRepresentedGroups(Vector<int[]> newRepGroups)
  {
    representedGroups = newRepGroups;
  }

  public void setComponentAscriptives(Vector<String> newComponentAscriptives)
  {
    componentAscriptives = newComponentAscriptives;
  }

  public void printReprsentedGroups()
  {
    String toPrint = "<";
    for (int i = 0; i < representedGroups.size()-1; i++)
    {
      if (i != 0)
        toPrint += " ";

      toPrint += getRepGroupString((representedGroups.get(i))) + ", \n";
    }
    toPrint += " " + getRepGroupString(representedGroups.get(representedGroups.size() - 1)) + ">";

    System.out.println(toPrint);
  }

  public String getRepGroupString(int[] input)
  {
    String ret = "[";

    for (int i = 0; i < input.length-1; i++)
    {
      ret += input[i] + ", ";
    }
    ret += input[input.length - 1] + "]";

    return ret;
  }
}
